package dbops

import "github.com/labstack/gommon/log"

func ReadVideoDeletionRecord(count int) ([]string, error) {
	stmtOut, err := dbConn.Prepare("SELECT video_name FROM video_del_rec LIMIT ?")
	var names []string
	if err != nil {
		return names, err
	}
	rows, err := stmtOut.Query(count)
	if err != nil {
		log.Printf("Query VideoDeletionRecord error: %v", err)
		return names, err
	}
	for rows.Next() {
		var name string
		if err := rows.Scan(&name); err != nil {
			return names, err
		}
		names = append(names, name)
	}
	defer stmtOut.Close()
	return names, nil
}

func DelVideoDeletionRecord(videoName string) error {
	stmtDel, err := dbConn.Prepare("DELETE FROM video_del_rec WHERE video_name = ?")
	if err != nil {
		return err
	}
	_, err = stmtDel.Exec(videoName)
	if err != nil {
		log.Printf("Deleting VideoDeletionRecord error: %v", err)
		return err
	}
	defer stmtDel.Close()
	return nil
}
